import { getProjectUserInfo } from '@neu/dcom-ui/api/institutions'

const state = {
  inspectionSearchObj: null,
  projectUserInfo: null
}

const mutations = {
  SET_INSPECTIONSEARCHOBJ: (state, inspectionSearchObj) => {
    state.inspectionSearchObj = inspectionSearchObj
  },
  RESET_INSPECTIONSEARCHOBJ: (state) => {
    state.inspectionSearchObj = null
  },
  SET_PROJECTUSERINFO: (state, info) => {
    state.projectUserInfo = info
  }
}

const actions = {
  setInspectionSearchObj({ commit }, inspectionSearchObj) {
    commit('SET_INSPECTIONSEARCHOBJ', inspectionSearchObj)
  },
  resetInspectionSearchObj({ commit }) {
    commit('RESET_INSPECTIONSEARCHOBJ')
  },
  getProjectUserInfo({ commit }) {
    return new Promise((resolve, reject) => {
      getProjectUserInfo().then(response => {
        const { data } = response
        commit('SET_PROJECTUSERINFO', data)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}

const getters = {
  projectUserInfo: state => state.projectUserInfo
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
